import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;

// 演示 自动刷新 页面, 设置 Header 的 Refresh
@WebServlet("/autoRefresh")
public class AutoRefreshServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setHeader("Refresh", "1");
        resp.setContentType("text/html; charset=utf8");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        resp.getWriter().write("时间戳: <h3>" + System.currentTimeMillis() + "</h3></br>"
                + "时间：<h3>" + sdf.format(System.currentTimeMillis()) + "</h3>");
    }
}
